<?php
if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
echo $header;
?>
<!-- postview -->
<div class="main postview">
    <?php if ( isset( $messageBox ) )
    { ?>
        <?php echo $messageBox; ?>
<?php }
else
{ ?>
        <ul class="infomation">
            <li><h3><?php echo $postData['title']; ?> <small><?php if ( $postData['ispersonal'] )
    { ?>个人<?php }
    else
    { ?>经纪<?php } ?>房源</small></h3></li>
            <li>在<strong><?php echo $postData['zonename']; ?></strong> <?php echo $postData['road']; ?> <strong><?php echo $postData['floor']; ?></strong>楼</li>
            <li><?php echo $postData['roomname']; ?></li>
            <li>居住面积 <?php echo $postData['square']; ?> m²</li>
    <?php if ( $postData['type'] <= 2 )
    { ?>
                <li>租金<strong><?php echo number_format( $postData['amount'], 2, '.', '' ); ?></strong>元 / 月</li>
    <?php }
    else
    { ?>
                <li>每平方售价 <strong><?php echo number_format( $postData['amount'], 2, '.', '' ); ?></strong> / m²</li>
                <li>总售价 <strong><?php echo number_format( $postData['square'] * $postData['amount'], 2, '.', '' ); ?></strong> 元</li>
    <?php } ?>
            <li class="desciption">
                <div class="entry"><?php echo $postData['content']; ?></div>
            </li>
            <li class="posttime">
                最初发布于<small><?php echo my_dateformat( $postData['addtime'] ); ?> <?php echo my_dateformat( $postData['addtime'], 'Y/m/d H:i' ); ?></small>
                更新时间<small><?php echo my_dateformat( $postData['updatetime'] ); ?> <?php echo my_dateformat( $postData['updatetime'], 'Y/m/d H:i' ); ?></small>
            </li>
        </ul>
        <div class="r">
            <div class="rbox contact">
                <h3>发布人</h3>
                <ul>
                    <li class="username">自己</li>
                </ul>
            </div>
        </div>
        <div class="c"></div>
        <h3>已有留言/评论(<?php echo count( $postComment ); ?>)</h3>
        <ul class="list">
    <?php foreach ( $postComment as $single ) { ?>
            <?php if( !$single['isapply'] ) { ?>
                <li><strong><?php echo $single['username']; ?></strong> 在 <?php echo my_dateformat( $single['addtime'] ); ?> 评论道：</li>
                <li id="comment_<?php echo $single['id']; ?>" class="comment_content">
                    <p><?php echo $single['content']; ?></p> 
                    <?php if( !isset( $replyComment[$single['id']] ) ) { ?>
                    <a class="reply_btn" href="javascript:void(0);" rel="<?php echo $single['id']; ?>">回复ta</a>
                    <?php } ?>
                </li>
                <?php if( isset( $replyComment[$single['id']] ) ){ ?>
                <li class="reply_content"> 我在 <?php echo my_dateformat( $replyComment[$single['id']]['addtime'] ); ?> 回复道：
                    <p><?php echo $replyComment[$single['id']]['content']; ?></p>
                </li>
                <?php } ?>
            <?php } ?>
    <?php } ?>
        </ul>
<?php } ?>
</div>
<!-- postview -->
<script>
    $(document).ready(function(){
        $('.reply_btn').click(function() {
            var reply = window.prompt('回复', '');
            var commentid = $(this).attr('rel');
            if ( reply ) {
                //ajax获取信息未回复评论数
                var loadingImg = '<img src="<?php echo config_item( 'base_url' ) . 'image/loading.gif'; ?>" class="post_loading" />';
                $.ajax({
                    type: 'POST',
                    url: '<?php my_url( 'userinfo', 'ajaxReplyComment' ); ?>',
                    data: 'reply=' + reply + '&commentid=' + commentid,
                    error: function(){
                        alert('回复失败请重试');
                    },
                    beforeSend: function(){
                        //
                    },
                    success: function(data){
                        if ( data == 1 ) {
                            $('#comment_' + commentid).append('<li class="reply_content"> 我刚回复道：<p>' + reply + '</p></li>');
                        }
                    }
                });
            }
        })
    });
</script>
<?php echo $footer; ?>